let _index = 0, progress = 0

export default function(images, callback){

	let onloadImg = () => {
		return new Promise((resolve, reject) => {
			var image = new Image();
			image.src = images[_index];
			image.onload = function(e){
				if(image.complete == true){
					_index ++;

					let pos = Math.floor((_index / images.length) * 100)

					progress = pos >= 100? 100: pos

					if(_index < images.length){
						load(images, callback);
					}else{
						if(callback && typeof callback === 'function'){
							callback();
						}
					}
					return resolve(progress)
				}
			}
		})
	}

	let load = async (images, callback) => {
		let progress = await onloadImg()
		return progress
	}


	load(images, callback)
}
